#include "pch.h"
#include <GGenericInfra/GPtr.h>
#include "GDxMesh.h"
#include <algorithm>

GDxMesh::GDxMesh(ID3D11Device* device, GRiMeshData meshData)
{
	Create(device, meshData);
}


void GDxMesh::Create(ID3D11Device* device, GRiMeshData meshData)
{
	MeshData = meshData;

	mVIBuffer.reset(new GDxVertexIndexBuffer(device, meshData.Vertices, meshData.Indices));

	GMath::Vector3 vi{ meshData.Vertices[0].Position };
	GMath::Vector3 vx = vi;
	for (auto& vert: meshData.Vertices)
	{
		for (int i = 0;i < 3;i ++)
		{
			vi[i] = std::fminf(vi[i], vert.Position[i]);

			vx[i] = std::fmaxf(vx[i], vert.Position[i]);
		}
		
	}
	Box.InitFromPoints(vi, vx);
	HR(mVIBuffer != nullptr);
}

